for epoch in range(15): 
    outputs = model(inputs) # inputs:(batch,seqlen) (1,5)
    # outputs:(batch,seqlen,num_class) (1,5,4) 
    pred = outputs.permute(0, 2, 1) 
    # (batch,num_class,seqlen,) (1,4,5) 
    labels = labels.view(-1,5) 
    # labels是（batchsize,seqlen） (1,5) 
    loss = criterion(pred,labels)
    optimizer.zero_grad()
    loss.backward()
    optimizer.step()
    _,idx = pred.max(dim=1) 
    # pred:(batch,num_class,seqlen,) (1,4,5)
    # max(dim=1)求维度1上最大值,
    # 消除形状(1,4,5)中dim=1维度,得到(1,5) 
    # idx:(1,5) tensor([[3, 0, 0, 3, 3]]) 

    idx = idx.view(5,).data.numpy() #[3, 0, 0, 3, 3]
    print("Pred:",''.join([idx2char[x] for x in idx]))
    print(",Epoch {}/15 loss={:.3f}". format(epoch+1,loss.item())) 
